package com.ruoyi.web.controller.book;

import java.util.List;

import com.ruoyi.module.business.CmBookInfoExtBusiness;
import com.ruoyi.module.domain.BookExtInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 图书扩展信息Controller
 *
 * @author ruoyi
 * @date 2022-04-13
 */
@RestController
@RequestMapping("/system/ext")
@RequiredArgsConstructor
public class CmBookInfoExtController extends BaseController {

    private final CmBookInfoExtBusiness cmBookInfoExtBusiness;

    /**
     * 查询图书扩展信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:ext:list')")
    @GetMapping("/list")
    public TableDataInfo list() {
        startPage();
        List<BookExtInfo> list = cmBookInfoExtBusiness.selectCmBookInfoExtList();
        return getDataTable(list);
    }

    /**
     * 获取图书扩展信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ext:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(cmBookInfoExtBusiness.selectCmBookInfoExtById(id));
    }

    /**
     * 新增图书扩展信息
     */
    @PreAuthorize("@ss.hasPermi('system:ext:add')")
    @Log(title = "图书扩展信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BookExtInfo cmBookInfoExt) {
        return toAjax(cmBookInfoExtBusiness.insertCmBookInfoExt(cmBookInfoExt));
    }

    /**
     * 修改图书扩展信息
     */
    @PreAuthorize("@ss.hasPermi('system:ext:edit')")
    @Log(title = "图书扩展信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BookExtInfo cmBookInfoExt) {
        return toAjax(cmBookInfoExtBusiness.updateCmBookInfoExt(cmBookInfoExt));
    }

    /**
     * 删除图书扩展信息
     */
    @PreAuthorize("@ss.hasPermi('system:ext:remove')")
    @Log(title = "图书扩展信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(cmBookInfoExtBusiness.deleteCmBookInfoExtByIds(ids));
    }
}
